package first.forHuaWei.贪心;

/**
 * @ClassName LC55
 * @description:
 * @author: 荣燊
 * @create: 2021-09-05 21:51
 **/
public class LC55 {
    // 跳跃游戏
    public static void main(String[] args) {
        int[] a = {2, 3, 1, 1, 4};
        System.out.println(canJump(a));
    }

    // 记录每一步可以调到的最大位置
    public static boolean canJump(int[] nums) {
        int length = nums.length;
        int maxLength = 0;
        for (int i=0; i<length; i++) {
            if (i <= maxLength) {
                maxLength = Math.max(i+nums[i], maxLength);
                if (maxLength >= length-1) {
                    return true;
                }
            }
        }
        return false;
    }
}
